package com.ruoyi.web.controller.material.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.controller.material.entity.request.ItemCategoryAddRequest;
import com.ruoyi.web.controller.material.entity.request.SupplierAddRequest;
import com.ruoyi.web.controller.material.entity.ylProductCategory;
import com.ruoyi.web.controller.material.service.ItemCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

/**
 * 物品分类管理Controller
 *
 * @author jzx
 * @date 2025-10-21
 */

@RestController
@RequestMapping("/admin/ItemCategory")
public class ItemCategoryController extends BaseController {
    @Resource
    private ItemCategoryService itemCategoryService;


    @PermitAll
    @Anonymous
    @GetMapping("/listAll")  // /admin/Supplier/page
    @Operation(summary = "物品分类列表查询")
    public TableDataInfo getListAll() {
        List<ylProductCategory> list = itemCategoryService.getPage();
        return getDataTable(list);
    }

    @PermitAll
    @Anonymous
    @GetMapping("/page")  // /admin/Supplier/page
    @Operation(summary = "物品分类列表查询")
    public TableDataInfo getPage() {
        startPage();
        List<ylProductCategory> list = itemCategoryService.getPage();
        return getDataTable(list);
    }


    @PermitAll
    @Anonymous
    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public AjaxResult delete(@PathVariable Long[] id) {
        itemCategoryService.delete(id);
        return success();
    }

    //ItemCategoryAddRequest
    @PermitAll
    @Anonymous
    @PostMapping("/add")
    @Operation(summary = "新增物品分类")
    public AjaxResult add(@Validated @RequestBody ItemCategoryAddRequest itemCategoryAddRequest) {
        itemCategoryService.add(itemCategoryAddRequest);
        return success();
    }


    @GetMapping(value = "/{id}")
    @Operation(summary = "查询明细")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(itemCategoryService.selectById(id));
    }

    @PermitAll
    @Anonymous
    @PostMapping("/update")
    @Operation(summary = "修改物品分类")
    public AjaxResult update(@Validated @RequestBody ItemCategoryAddRequest itemCategoryUpdateRequest) {
        itemCategoryService.update(itemCategoryUpdateRequest);
        return success();
    }

}
